package com.xinou.daily_report.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinou.common.base.config.ApiResponse;
import com.xinou.common.base.exception.BusException;
import com.xinou.common.util.BeanUtil;
import com.xinou.daily_report.PO.rule.RuleListPO;
import com.xinou.daily_report.PO.rule.RuleUpdatePO;
import com.xinou.daily_report.VO.RulesInfoVO;
import com.xinou.daily_report.entity.SysDaily;
import com.xinou.daily_report.entity.SysRules;
import com.xinou.daily_report.mapper.SysRulesMapper;
import com.xinou.daily_report.service.SysRulesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-07-08
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysRulesServiceImpl extends ServiceImpl<SysRulesMapper, SysRules> implements SysRulesService {



    @Override
    public ApiResponse<RulesInfoVO> ruleList(RuleListPO po) {
        Page<SysRules> page = new Page<>(po.getPageNumber(), po.getPageSize());
        Page<SysRules> rulesList = page(
                page,
                null
        );
        return new ApiResponse<>(BeanUtil.listA2ListB(rulesList.getRecords(),RulesInfoVO.class),rulesList.getTotal());
    }

    @Override
    public ApiResponse<Void> ruleUpdate(RuleUpdatePO po) {
        if(!updateById(BeanUtil.beanA2beanB(po,SysRules.class))){
            throw new BusException("修改失败");
        }
        return new ApiResponse<>();
    }
}
